<template>
  <div>
  <div id="box">

  </div>
  </div>
</template>
<script>
import * as echarts from "echarts";
import {mapGetters,mapActions} from "vuex"
  export default {
    data() {
      return {
      }
    },
    methods: {
      ...mapActions({
        asyncList:"cate/asyncList"
      })
    },
    computed:{
  ...mapGetters({
    list:"cate/list"
  })
    },
    watch:{
      list:{
        handler(){
          var myChart = echarts.init(document.getElementById('box'));

      // 指定图表的配置项和数据
      var option = {
        title: {
          text: '子数量'
        },
        tooltip: {},
        legend: {
          data: ['数量']
        },
        xAxis: {
          data: this.list.map((item) => {
              return item.catename;
          })
        },
        yAxis: {},
        series: [
          {
            name: '数量',
            type: 'bar',
            data: this.list.map((item) => {
                return item.children.length;
          })
          }
        ]
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
        }
      }
    },
    components: {},
    mounted() {
      this.asyncList()
    },
    destroyed() {},
  }
</script>
<style scoped>
#box{
  width:100%;
  height: 400px;
  border: 1px solid red;
}
</style>